package ru.sushka.lunch.gui.views;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

import ru.sushka.lunch.dao.files.FileCustomerDao;
import ru.sushka.lunch.enitiy.Customer;
import ru.sushka.lunch.gui.controllers.*;
import ru.sushka.lunch.gui.models.*;

public class MainForm {

    /**
     * Launch the application.
     * @param args
     */
    public static void main(String[] args) {
        try {
            MainForm window = new MainForm();
            window.open();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Open the window.
     */
    public void open() {
        Display display = Display.getDefault();
        final Shell shell = new Shell();
        shell.setSize(426, 265);
        shell.setText("Lunchy: система заказа обедов");
        shell.setLayout(new GridLayout(1, false));
        
        Composite composite = new Composite(shell, SWT.NONE);
        composite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
        RowLayout rl_composite = new RowLayout(SWT.HORIZONTAL);
        rl_composite.center = true;
        composite.setLayout(rl_composite);
        
        Label lblNewLabel = new Label(composite, SWT.NONE);
        lblNewLabel.setText("Пользователь:");
        
        Combo combo = new Combo(composite, SWT.READ_ONLY);
        combo.setItems(new String[] {"Firstname Lastname"});
        combo.setLayoutData(new RowData(277, SWT.DEFAULT));
        combo.select(0);
        
        Composite composite_1 = new Composite(shell, SWT.NONE);
        RowLayout rl_composite_1 = new RowLayout(SWT.HORIZONTAL);
        rl_composite_1.justify = true;
        rl_composite_1.spacing = 10;
        rl_composite_1.fill = true;
        composite_1.setLayout(rl_composite_1);
        GridData gd_composite_1 = new GridData(SWT.CENTER, SWT.FILL, false, true, 1, 1);
        gd_composite_1.heightHint = 189;
        gd_composite_1.widthHint = 262;
        composite_1.setLayoutData(gd_composite_1);
        
        Button menuBtn = new Button(composite_1, SWT.NONE);
        menuBtn.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                MenuModel menuModel = new MenuModel();
                MenuController menuController = new MenuController(menuModel);
            }
        });
        menuBtn.setLayoutData(new RowData(100, 50));
        menuBtn.setText("Меню");
        
        Button orderBtn = new Button(composite_1, SWT.NONE);
        orderBtn.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                //заглушка
                FileCustomerDao dao = new FileCustomerDao();
                Customer customer = dao.get(1);
                OrderModel orderModel = new OrderModel();
                OrderController orderController = new OrderController(orderModel, customer);
            }
        });
        orderBtn.setLayoutData(new RowData(100, 50));
        orderBtn.setText("Заказ");
        
        Button CourseBtn = new Button(composite_1, SWT.NONE);
        CourseBtn.setEnabled(false);
        CourseBtn.setLayoutData(new RowData(100, 50));
        CourseBtn.setText("Блюда");
        
        Button CustomerBtn = new Button(composite_1, SWT.NONE);
        CustomerBtn.setEnabled(true);
        CustomerBtn.setLayoutData(new RowData(100, 50));
        CustomerBtn.setText("Пользователи");
        CustomerBtn.addSelectionListener(new SelectionAdapter() {
        	@Override
        	public void widgetSelected(SelectionEvent arg0) {
        		MessageBox messageBox = new MessageBox(shell, SWT.OK | SWT.CANCEL);
        	    messageBox.setMessage("Users should be here");
        	    messageBox.setText("Users");
        	    int rc = messageBox.open();
        	}
		});
        
        Button optionsBtn = new Button(composite_1, SWT.NONE);
        optionsBtn.setEnabled(false);
        optionsBtn.setLayoutData(new RowData(100, 50));
        optionsBtn.setText("Настройки");
        
        Button exitBtn = new Button(composite_1, SWT.NONE);
        exitBtn.setEnabled(false);
        exitBtn.setLayoutData(new RowData(100, 50));
        exitBtn.setText("Выход");

        shell.open();
        shell.layout();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }
}
